package com.dao;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.util.*;
import entities.Product;
import entities.Users;
import com.exception.*;

public class CheckOUtProducts{
	public int buyProduct(Users u,Product p,int num)throws Exception{
		Session session = null;
		Product dec=null;
		try{
			session =HbnUtil.getSession();
			session.beginTransaction();
			dec =(Product) session.createQuery("from Product as p " +
												"where p.Name='"+
												p.getName()+"'")
												.uniqueResult();
		
			session.update(dec);
			session.beginTransaction().commit();	
			
		}catch(HibernateException hs){
			session.beginTransaction().rollback();
			
		}
		return -1;
	}
}
